
* Formatting
graph set window fontface "Times New Roman"	// use Times New Roman as the default font for Graph window
// 	 graph set window fontface default 			// use this to restore to factury setting if preferred later

set scheme s1mono


********************************************************************
*************** Prepare the data ***************
use "${ddata}cleaned_data_wACSweight.dta", clear

keep userid treatment sce state white age male college married working_ft child_under_6 child_under_18 lincome current_censusdiv
sort userid sce

save "${ddata}data_demographics", replace



use "${ddata}cleaned_data_wACSweight.dta", clear            

forvalues i=0(1)5 {

	xtile quartile_gap_`i' = original_gap`i'		, n(4)
	xtile quartile_so_`i'  = so_mother_time_off_`i' , n(4)

	gen l_quartile_gap_`i' =  quartile_gap_`i'==1 					   if quartile_gap_`i'~=. 
	gen iqr_gap_`i'		   = (quartile_gap_`i'==2|quartile_gap_`i'==3) if quartile_gap_`i'~=.
	gen h_quartile_gap_`i' =  quartile_gap_`i'==4 					   if quartile_gap_`i'~=. 

	gen 	group_`i'=1 if l_quartile_gap_`i'==1
	replace group_`i'=2 if 		  iqr_gap_`i'==1
	replace group_`i'=3 if h_quartile_gap_`i'==1
}

keep userid sce qs2_*  group_*

reshape long qs2_ group_, i(userid sce) j(questions)
drop if qs2_==.
rename qs2_ qs2
rename group_ group


gen group1 = group==1 if group~=.
gen group2 = group==2 if group~=.
gen group3 = group==3 if group~=.

sort userid sce
merge m:1 userid sce using "${ddata}data_demographics"

forvalues i=1(1)3 {

	gen group`i'_t = group`i'*treatment

}





********************************************************************
*************** Figure 3: Mechanism (BOTH GENDERS) ***************
label var group1_t "Bottom Quartile PG (Avg PG<0)"
label var group2_t "Middle 50% PG (Avg PG~0)"
label var group3_t "Top Quartile PG (Avg PG>0)"

forvalues i=0(1)5 {

	regress qs2 group1_t group2_t group3_t group1 group2 group3 if question==`i', robust

	estimates store F`i'

}


#delimit;
coefplot (F1, keep(group1_t group2_t group3_t) m(circle)  ) 
(F2, keep(group1_t group2_t group3_t) m(diamond) )
(F3, keep(group1_t group2_t group3_t) m(square) )
(F4, keep(group1_t group2_t group3_t) m(triangle) )
(F5, keep(group1_t group2_t group3_t) m(X) ), 
vertical ytitle("Treatment Effect (percentage points)", size(small)) 
yline(0) xlabel(,labs(small)) ylabel(,labs(small)) 
legend( rows(1) size(small) subtitle("Mother earns:", size(small)) label(2 "15% less") label(4 "Same") label(6 "15% more") label(8 "30% more") label(10 "50% more") ) 
title("B. Scenario 2", size(12pt))  legend(region(lstyle(none)));
graph export "${o}treatment_by_pg_q2.pdf", replace;	 

#delimit;
coefplot (F0, keep(group1_t group2_t group3_t)  
bcolor(gray%40)), vertical recast(bar)  barwidth(0.5) fcolor(*.8)  
ytitle("Treatment Effect (percentage points)", size(small)) yline(0) 
xlabel(,labs(small)) ylabel(,labs(small)) legend( off) title("A. Scenario 1", size(12pt))    ;
graph export "${o}treatment_by_pg_q1.pdf", replace;	


#delimit cr


